<template>
	<view>
	  <view class="scroll-container">
	  	<!-- 左侧 -->
	  	<scroll-view scroll-y="true" class="left-scroll-view" :style="{height: wh + 'px'}">
	  		<block v-for="(item, i) in cateList" :key="item.id">
					<view :class="['left-scroll-view-item', i === active ? 'active' : '']" @click="activeChange(i)">{{item.cat_name}}</view>
				</block>
	  	</scroll-view>
	  	<!-- /左侧 -->
	  	<!-- 右侧 -->
	  	<scroll-view scroll-y="true" class="right-scroll-view" :style="{height: wh + 'px'}" :scroll-top="scrollTop">
				<!-- 二级分类 -->
	  		<block v-for="(item2, i2) in cateLevel2" :key="i2">
					<view class="cate-lv2-title">
						/ {{item2.cat_name}} /
					</view>
					<!-- 二级分类下的三级分类 -->
					<view class="cate-lv3-list">
						<view class="cate-lv3-item" v-for="(item3, i3) in item2.children" :key="i3" @click="toGoodsList(item3)">
							<image src="http://157.122.54.189:6005/pyg/pic_floor01_1@2x.png"></image>
							<!-- <image :src="item3.cat_icon"></image> -->
							<text>{{item3.cat_name}}</text>
						</view>
					</view>
					<!-- /二级分类下的三级分类 -->
				</block>
				<!-- /二级分类 -->
	  	</scroll-view>
	  	<!-- /右侧 -->
	  </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wh: uni.getSystemInfoSync().windowHeight,
				// 分类数据列表
				cateList: [],
				// 当前激活项
				active: 0,
				// 二级分类列表
				cateLevel2: [],
				// 滚动距离
				scrollTop: 0
			};
		},
		onLoad() {
			this.getCateList()
		},
		methods: {
			async getCateList() {
				const { data } = await uni.$http.get('/api/public/v1/categories')
				// console.log(data)
				if(data.meta.status !== 200) return uni.$showMsg()
				this.cateList = data.message
				this.cateLevel2 = data.message[0].children
			},
			// 点击左侧分类
			activeChange(i) {
				this.active = i
				this.cateLevel2 = this.cateList[i].children
				this.scrollTop = this.scrollTop === 0 ? 1 : 0
			},
			// 跳转到对应的商品界面
			toGoodsList(item) {
				console.log(item)
				// console.log('123')
				uni.navigateTo({
					url: "/subpkg/goods_list/goods_list?cid=" + item.cat_id
				})
			}
		}
	}
</script>

<style lang="scss">
  .scroll-container {
		display: flex;
		.left-scroll-view{
			width: 120px;
			.left-scroll-view-item {
				position: relative;
				line-height: 60px;
				background-color: #F7F7F7;
				text-align: center;
				font-size: 12px;
				&.active {
					background-color: #FFFFFF;
					&::before {
						content: ' ';
					  position: absolute;
						top: 50%;
						transform: translateY(-50%);
						left: 0;
						width: 1px;
						height: 30px;
						background-color: #C00000;
					}
				}
			}
		}
		.right-scroll-view{
			.cate-lv2-title{
				font-size: 24rpx;
				font-weight: bold;
				text-align: center;
				padding: 15px 0;
			}
			.cate-lv3-list{
				display: flex;
				flex-wrap: wrap;
				.cate-lv3-item{
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					width: 33.3%;
					margin-bottom: 10px;
					font-size: 12px;
					image{
						width: 60px;
						height: 60px;
					}
				}
			}
		}
	}
</style>
